﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SF.Utilities;
using System.Data;

namespace SF.WebClient.Helper
{
    /// <summary>
    /// test1 的摘要说明
    /// </summary>
    public class test1 : IHttpHandler
    {

        public class Temp1
        {
            public string ID { get; set; }

            public string Code { get; set; }
        }

        public void ProcessRequest(HttpContext context)
        {
            Dictionary<string, object> result = new Dictionary<string, object>();

            var data = new List<dynamic> { new { id = 1, name = "测试1" }, new { id = 3, name = "测试3" }, new { id = 2, name = "测试2" } };
            result.Add("e2", data.OrderBy(o => o.id));

            var dt = new DataTable();
            dt.Columns.Add("ID");
            dt.Columns.Add("Code");

            var row1 = dt.NewRow();
            row1["ID"] = "110";
            row1["Code"] = "1234";
            dt.Rows.Add(row1);

            var row2 = dt.NewRow();
            row2["ID"] = "111";
            row2["Code"] = "77";
            dt.Rows.Add(row2);

            List<Temp1> data2 = dt.ToList<Temp1>();
            result.Add("e99", data2.OrderBy(o => float.Parse(o.Code)));


            context.Response.ContentType = "application/json";
            context.Response.Write(result.ToJson());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}